package com.ccys.cms.controller.corporateAndInsurance;


import com.ccys.cms.service.corporateAndInsurance.CDMPBenefitPricingService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.web.productAndService.NumEnum;
import com.ccys.db.entity.TblCdmpBenefitPricing;
import com.ccys.db.entity.TblPlan;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/corporateAndInsurance")
@Api(tags = "pricing plan")
public class CDMPBenefitPricingController {


    @Resource
    private CDMPBenefitPricingService service;


    @PostMapping("cdmpBenefitPricing")
    @ApiOperation("新增")
    @Transactional
    public ResponseResult insert(TblCdmpBenefitPricing model) {

        int i = service.insertOrUpdate(model);
        return ResponseResult.update(i);
    }



    @PutMapping("cdmpBenefitPricing")
    @ApiOperation("修改")
    @Transactional
    public ResponseResult update(TblCdmpBenefitPricing model) {

        int i = service.insertOrUpdate(model);
        return ResponseResult.update(i);
    }


    @GetMapping("cdmpBenefitPricing/detail")
    @ApiOperation("根据id查询")
    public ResponseResult<TblPlan, Object> getById(String id) {

        return ResponseResult.success(service.findEntityById(id));
    }


    @DeleteMapping("cdmpBenefitPricing")
    @ApiOperation("根据Id删除")
    @Transactional
    public ResponseResult delete(String id) {

        TblCdmpBenefitPricing model = new TblCdmpBenefitPricing();
        model.setId(id);
        model.setDelFlag(NumEnum.DEL.getCode());
        int i = service.updateEntityById(model);
        return ResponseResult.update(i);
    }


    @GetMapping("cdmpBenefitPricing/list")
    @ApiOperation(value = "查询集合")
    public ResponseResult<TblCdmpBenefitPricing, Object> getList(String benefitId) {

        List<TblCdmpBenefitPricing> pricingList = service.findListByLimit(TblCdmpBenefitPricing.class, new ArrayList<String>() {{
            add(" del_flag = 0 ");
            add(" benefit_id = '" + benefitId + "'");
        }}, "created_on desc");

        return ResponseResult.success(pricingList);
    }

}
